<html>
 <body>
 
<?php
 $soln = $_POST["expr"];
 $text = "Solution: ";
 echo $text;
 $err1 = "ERROR: Invalid expression";

 if (preg_match('/^([0-9]|\+|\-|\*|\/|\.| )*$/', $soln)) {
	
	if (preg_match('/(\+|\-|\*|\/)(\+|\*|\/)+/', $soln)
		|| preg_match('/\-\-/', $soln)
		|| preg_match('/\.\./', $soln)
		|| preg_match('/ \. /', $soln)
		|| preg_match('/\/0($|\+|\-|\*|\/| )/', $soln))
		echo $err1;
	else {
		$exp = "return ".$soln.";";
 		$soln2 = eval($exp);
		echo $soln2;
	}

 }
 else
	echo $err1;
?>

<form method="post" action="calculator.php">
<input type="text" name="expr"><input type="submit" value="Calculate">
</form> 
 
</body>
</html> 
